public class Solution2222 {
    public long numberOfWays(String s) {
        long ans=0;
        long[] f=new long[s.length()+1];
        for (int i=0;i<s.length();i++){
            f[i+1]=f[i]+(s.charAt(i)=='0'?1:0);
        }
        long[] g=new long[s.length()+1];
        for (int i=s.length()-1;i>=0;i--){
            g[i]=g[i+1]+(s.charAt(i)=='0'?1:0);
        }
        for (int i=0;i<s.length();i++){
            long left=s.charAt(i)=='1'?f[i]:i-f[i];
            long right=s.charAt(i)=='1'?g[i+1]:s.length()-i-1-g[i+1];
            ans+=left*right;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2222().numberOfWays("001101"));
    }
}
